﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cn.Edwon.Web.Support;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using Cn.Cellula.Model.Security;
using System.Collections.Generic;
using System.Xml;
using Cn.Edwon.Web;
using Cn.Cellula.Model.Calendar;
using Cn.Cellula.Biz;
using Cn.Cellula.Biz.Def;

namespace Cn.Cellula.Website.Admin {
    public partial class Default : PageSupport {
        protected void Page_Load(object sender, EventArgs e) {
            if (!Page.IsPostBack) {
                LoadUserInfo();
                LoadTodoList();
                LoadLastTodoList();
            }
        }
        private void LoadUserInfo() { 
            IUserBiz biz = BizFactory.Get<IUserBiz>();
            try {
                VSysUserEO eo = biz.Load<VSysUserEO>(this.Actor.ID);
                this.lab_Dept.Text = eo.DeptName;
                this.lab_Duty.Text = eo.Duty;
                this.lab_RoleName.Text = eo.RoleName;
                this.lab_UserName.Text = eo.UserName;
                if (String.IsNullOrEmpty(eo.CoverPath))
                    this.img_Face.ImageUrl = "/cellula_client/default/face/default" + eo.Gender + ".png";
                else
                    this.img_Face.ImageUrl = eo.CoverPath;
            } catch { }
        }
        private void LoadTodoList() {
            DateTime dt = DateTime.Now;
            String from = dt.Year + "-" + dt.Month + "-" + dt.Day + " 0:0:1";
            String to = dt.Year + "-" + dt.Month + "-" + dt.Day + " 23:59:59";
            this.lab_Today.Text = dt.Year + "-" + dt.Month + "-" + dt.Day;
            IList<VCalendarTodoEO> list = BizFactory.Get<ICalendarBiz>().LoadCalendarTodo(this.OwnerKey, this.Actor.ID, from, to,TodoStatus.All);
            this.gvTodo.DataSource = list;
            this.gvTodo.DataBind();
        }
        private void LoadLastTodoList() {
            DateTime fromdt = DateTime.Now.AddYears(-1);
            DateTime todt = DateTime.Now;
            String from = fromdt.Year + "-1-1 0:0:1";
            String to = todt.Year + "-" + todt.Month + "-" + todt.Day + " 0:0:0";
            IList<Object> list = BizFactory.Get<ICalendarBiz>().LoadCalendarTodo(this.OwnerKey, this.Actor.ID, from, to, TodoStatus.Started,10);
            this.gvLastDays.DataSource = list;
            this.gvLastDays.DataBind();
        }
        private void GotoFirstMenuItem() {
            IUserBiz biz = BizFactory.Get<IUserBiz>();
            XmlDocument doc = biz.LoadFunction2XHtml(this.Actor, null);
            XmlElement root = doc.DocumentElement;
            XmlNodeList list = root.SelectNodes("//div[@url!='']");
            if (list != null && list.Count > 0) {
                XmlNode xn = list[0];
                XmlAttribute xa = xn.Attributes["url"];
                String url = xa.Value.ToString();
                Response.Redirect(ClientHelper.RootUrl + url, true);
                return;
            } else {
                Response.Redirect("User/EditProfile.aspx", true);
                return;
            }
        }
    }
}
